/*! \file togglebtn.h	
	This is the header file for togglebtn.cpp
	
	This contains the ButtonGroup and ToggleButton classes
*/

#ifndef TOGGLE_BUTTON_H
#define TOGGLE_BUTTON_H

#include "component.h"
#include "imgbtn.h"
#include "listener.h"
#include <string>
#include <list>

using namespace std;

class ButtonGroup;

/**
	\class ToggleButton

	This represents radio buttons and checkboxes. These buttons are added to
	ButtonGroups to become radio buttons. If nothing is done, they are checkboxes.

	The only difference is the action taken on mouseDown. Radio buttons call toggle;
	checkboxes call setSelected.

*/
class ToggleButton: public ImageButton {
protected:
	ButtonGroup* group; // the group that this belongs to
	bool selected;
public:
	/**
	* Constructor
	* \param imageID			unselected ID (box unchecked, radio button not filled)
	* \param depressedImageID	selected ID (box is checked, radio button filled)
	*/
	ToggleButton( Component* parent, int imageID, int depressedImageID );

	/**
	* Change selected to !selected
	*/
	void toggle();

	/**
	* Change selected to parameter
	*/
	void setSelected( bool selected = true );

	/**
	* Returns true if this button is selected
	*/
	bool getSelected();
	
	/**
	* Draw
	*/
	void draw();
	
	/**
	* Radio buttons belong to a group so that only one can be selected at a time.
	* This function sets that group, however, it is ONLY called by ButtonGroup.
	*/
	void setGroup( ButtonGroup* g );

	virtual void performAction();
	
	virtual void mouseDown( Event e );
	
	virtual void keyDown( Event e );
};

/**
	\class ButtonGroup

	A ButtonGroup is not really a component, but when a dispose() function is made,
	these will need to be removed from memory, so it should be able to belong to a container.

	Since it's not truly component, there is nothing associated with its draw() function, and also
	it cannot have the focus.
*/
class ButtonGroup : public Component {
private:
	list<ToggleButton*> buttons;
	ToggleButton* selected;
public:
	/**
	* Constructor
	*/
	ButtonGroup( Component* parent );

	/**
	* Add a button to this group
	*/
	void add( ToggleButton* b );

	/**
	* Select a button in this group (if it's not in this ButtonGroup, this does nothing)
	*/
	void select( ToggleButton* b );

	/**
	* This does nothing
	*/
	void update() { }
	
	/**
	* This does nothing - there is nothing to draw
	*/
	void draw() { }
	
	/**
	* ButtonGroup can never have the focus (because what would it do with the focus...?)
	* so we override Component's return value for this. It will be skipped in tab traversals.
	*/
	bool canHaveFocus() { return false; }
	

};

#endif
